<?php
/**
 * JumpTo - A Download System for Content Pages. Work in Joomla 1.0.x & Joostina.
 * @author:      Лаборатория сайтов
 * @version:     1.3
 * @release:     2009.12.20
 * @package:     bot_JumpTo
 * @copyright:   (C) 2009 http://sitelab.net.ru
 * @license:     http://www.gnu.org/copyleft/gpl.html GNU/GPL
 *
 * Cоздан на базе Registered Downloads  (C) 2006 by St. John Johnson
 **/


#-Запрет прямого доступа-#
defined( '_VALID_MOS' ) or die();

global $mosConfig_lang;

$_MAMBOTS->registerFunction( 'onPrepareContent', 'botJumpTo' );

if (file_exists( JPATH_BASE.'/components/com_jumpto/lang/' . $mosConfig_lang . '.php')){
	include_once( JPATH_BASE.'/components/com_jumpto/lang/' . $mosConfig_lang . '.php' );
}else{
	include_once( JPATH_BASE.'/components/com_jumpto/lang/russian.php' );
}

function botJumpTo( $published, &$row, &$params, $page=0 ) {

	$regex = "#{jumpto*(.*?)}#s";

	if (!$published) {
		return true;
	}

	$row->text = preg_replace_callback( $regex, 'botJumpTo_replacer', $row->text );
	return true;
}

function botJumpTo_replacer( &$matches ) {

	$id = str_replace('id=','',$matches[1]);

	$query = "SELECT id,name,count FROM #__jumpto WHERE id=".$id;
	$row = database::getInstance()->setQuery( $query )->loadRow();

	if ($row) {
		return '<table style="border: 1px dashed #999999; font-size: 10px;" align="center" border="0" cellpadding="4" cellspacing="0" width="50%"><tbody><tr><td align="right" rowspan="2" valign="middle"><img src="'.JPATH_SITE.'/components/com_jumpto/images/jumpto_file.gif" alt="'.JUMPTO_DOWNLOAD_ALT.'"></td><td align="left"><a href="'.JPATH_SITE.'/index.php?option=com_jumpto&uid='.$row[0].'" target="_blank">'.JUMPTO_DOWNLOAD.'</a></td></tr><tr><td align="left">"'.$row[1].'" ( '.JUMPTO_LOADED.' "'.$row[2].'" ) </td></tr></tbody></table>';
	}
}